from selenium.webdriver.common.by import By
from base.mp.base import BasePage, BaseHandle


class HomePage(BasePage):
    def __init__(self):
        super().__init__()
        self.username = (By.CSS_SELECTOR, ".user-name")
        self.content_manage = By.XPATH, "//*[text()='内容管理']"
        self.publish_btn = By.XPATH, "//*[@class='sidebar-el-menu el-menu']/div[2]/li/ul/li[1]"

    def find_username(self):
        return self.get_element(self.username)

    def find_content_manage(self):
        return self.get_element(self.content_manage)

    def find_publish(self):
        return self.get_element(self.publish_btn)


class HomeHandle(BaseHandle):
    def __init__(self):
        self.home_page = HomePage()

    def get_username(self):
        return self.home_page.find_username().text

    def click_content_manage(self):
        self.home_page.find_content_manage().click()

    def click_publish_btn(self):
        self.home_page.find_publish().click()


class HomeProxy:
    def __init__(self):
        self.home_handle = HomeHandle()

    def get_username_msg(self):
        return self.home_handle.get_username()

    def go_publish_page(self):
        self.home_handle.click_content_manage()
        self.home_handle.click_publish_btn()
